#!/bin/bash

INPUT=$1
numerical_max_value=99999
numerical_min_value=0
chunksize=2500  # Optimal
#chunksize=25
prepend=", "
 
function read_numerical_file() {
	while IFS= read -r -n$chunksize chunk
	do
		echo "Chunk: $chunk"
		last="$(echo $chunk|grep -Po "\,\s*\d*$")"	
		echo "Last: $last"
		lastlen="$(echo $last|wc -c)"
		echo "Lastlength: $(echo $last|wc -c)"
		first="${chunk:0:-$lastlen}"
		echo "First: $first"
		all=$prepend$first	
		words="$(echo $first|grep -Po "(\s|\-)\w+")"
	  for word in $words 
	    do
				if [ $word -lt $numerical_min_value ]; then
		    	echo "min word: $word" 1>&2
		    	continue
				fi
				if [ $word -gt $numerical_max_value ]; then
		    	echo "max word: $word" 1>&2
		    	continue
				fi
		
				echo "num word: $word"
		
	  done
		prepend=$last
	break
	done < "$1"
}

read_numerical_file $INPUT
